package com.btb.adapter.schedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.btb.adapter.constant.Constants;
import com.btb.adapter.constant.EventType;
import com.btb.adapter.service.CallBackService;
import com.btb.adapter.service.OffChainService;
import com.btb.adapter.service.UpChainEvent;

import lombok.extern.slf4j.Slf4j;

/**
 * @author hqbzl 英雄和鱼下链任务
 */
@Slf4j
//@Component
@EnableScheduling
public class OffChainSchedule {
	@Autowired
	private  OffChainService offChainService;
	@Autowired
	private UpChainEvent upChainEvent;
	@Autowired
	private CallBackService callBackService;
	/**
	 * 下链处理任务
	 */
	@Scheduled(initialDelay = 100, fixedDelay = 1000 * 1)
	public void offChainSchedule() {
		log.error("offChainSchedule start");
		offChainService.offChain();
		log.error("offChainSchedule end");
	}

	/**
	 *
	 * 下链区块事件处理任务
	 */
	@Scheduled(initialDelay = 100, fixedDelay = 1000 * 1)
	public void offChainEventSchedule() {
		log.error("offChainEventSchedule start");
		upChainEvent.start(EventType.OFF_CHAIN, Constants.OFF_CHAIN_EVENT);
		log.error("offChainEventSchedule end");
	}

	/**
	 * 下链确认回调任务
	 */
	@Scheduled(initialDelay = 100, fixedDelay = 1000 * 1)
	public void callBackSchedule() {
		log.error("callBackSchedule start");
		callBackService.offChain();
		log.error("callBackSchedule end");
	}
}
